<template>
	<view class="wrap">
		<view class="comment">
			<view class="top">
				<view class="left">
					<view class="heart-photo">
						<image :src="comment.url" mode=""></image>
					</view>
					<view class="user-info">
						<view class="name">{{ comment.name }}</view>
						<view class="date">06-25 13:58</view>
					</view>
				</view>
				<view class="right" :class="{ highlight: comment.isLike }">
					{{ comment.likeNum }}
					<u-icon v-if="!comment.isLike" name="thumb-up" class="like" color="#9a9a9a" :size="30"
						@click="getLike"></u-icon>
					<u-icon v-if="comment.isLike" name="thumb-up-fill" class="like" :size="30" @click="getLike">
					</u-icon>
				</view>
			</view>
			<view class="content">{{ comment.contentText }}</view>
		</view>
		<view class="all-reply">
			<view class="all-reply-top">全部回复（{{ comment.allReply }}）</view>
			<view class="item" v-for="(item, index) in commentList" :key="index">
				<view class="comment">
					<view class="top">
						<view class="left">
							<view class="heart-photo">
								<image :src="item.url" mode=""></image>
							</view>
							<view class="user-info">
								<view class="name">{{ item.name }}</view>
								<view class="date">{{ item.date }}</view>
							</view>
						</view>
						<view class="right" :class="{ highlight: item.isLike }">
							<view class="num">{{ item.likeNum }}</view>
							<u-icon v-if="!item.isLike" name="thumb-up" class="like" :size="30" color="#9a9a9a"
								@click="getLike(index)"></u-icon>
							<u-icon v-if="item.isLike" name="thumb-up-fill" class="like" :size="30"
								@click="getLike(index)"></u-icon>
						</view>
					</view>
					<view class="reply" v-if="item.reply">
						<view class="username">{{ item.reply.name }}</view>
						<view class="text">{{ item.reply.contentStr }}</view>
					</view>
					<view class="content">{{ item.contentText }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commentList: [],
				comment: ''
			};
		},
		onLoad() {
			this.getReply();
		},
		methods: {
			// 点赞
			getLike(index) {
				if (index === 0 || index > 0) {
					this.commentList[index].isLike = !this.commentList[index].isLike;
					if (this.commentList[index].isLike == true) {
						this.commentList[index].likeNum++;
					} else {
						this.commentList[index].likeNum--;
					}
				} else {
					if (this.comment.isLike == true) {
						this.comment.isLike = !this.comment.isLike;
						this.comment.likeNum--;
					} else {
						this.comment.isLike = !this.comment.isLike;
						this.comment.likeNum++;
					}
				}
			},

			// 回复列表
			getReply() {
				this.comment = {
					id: 1,
					name: '亲爱的自己',
					date: '12-25 18:58',
					contentText: '今天打得好开心哇',
					url: '/static/icon/ui/user/avatar/1.png',
					allReply: 12,
					likeNum: 33,
					isLikes: false
				};
				this.commentList = [{
						name: '手心的蔷薇',
						date: '12-25 18:58',
						contentText: '哈哈哈是啊',
						url: '/static/icon/ui/user/avatar/2.png',
						likeNum: 33,
						isLike: false,
						reply: {
							name: '亲爱的自己',
							contentStr: '今天打得好开心哇'
						}
					},
					{
						name: '手心的蔷薇',
						date: '01-25 13:58',
						url: '/static/icon/ui/user/avatar/2.png',
						contentText: '上到了二阶了，哈哈',
						allReply: 0,
						likeNum: 11,
						isLike: false,
						reply: {
							name: '亲爱的自己',
							contentStr: '今天打得好开心哇'
						}
					},
					{
						name: '亲爱的自己',
						date: '03-25 13:58',
						contentText: '明天带你上三阶！',
						allReply: 0,
						likeNum: 21,
						url: '/static/icon/ui/user/avatar/1.png',
						isLike: false,
						allReply: 2,
						reply: {
							name: '手心的蔷薇',
							contentStr: '上到了二阶了，哈哈'
						}
					},
					{
						name: '豆豆',
						date: '06-20 13:58',
						contentText: '能带带我吗，我才一阶，这几天一直都上不去，我也不知道咋回事，可能没有你带我吧，啊哈哈哈哈',
						allReply: 0,
						likeNum: 150,
						url: '/static/icon/ui/user/avatar/3.png',
						isLike: false
					}
				];
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f2f2f2;
	}

	.comment {
		padding: 30rpx;
		font-size: 32rpx;
		background-color: #ffffff;

		.top {
			display: flex;
			justify-content: space-between;
		}

		.left {
			display: flex;

			.heart-photo {
				image {
					width: 64rpx;
					height: 64rpx;
					border-radius: 50%;
					background-color: #f2f2f2;
				}
			}

			.user-info {
				margin-left: 10rpx;

				.name {
					color: #5677fc;
					font-size: 28rpx;
					margin-bottom: 4rpx;
				}

				.date {
					font-size: 20rpx;
					color: $u-light-color;
				}
			}
		}

		.right {
			display: flex;
			font-size: 20rpx;
			align-items: center;
			color: #9a9a9a;

			.like {
				margin-left: 6rpx;
			}

			.num {
				font-size: 26rpx;
				color: #9a9a9a;
			}
		}

		.highlight {
			color: #5677fc;

			.num {
				color: #5677fc;
			}
		}
	}

	.all-reply {
		margin-top: 10rpx;
		padding-top: 20rpx;
		background-color: #ffffff;

		.all-reply-top {
			margin-left: 20rpx;
			padding-left: 20rpx;
			border-left: solid 4rpx #5677fc;
			font-size: 30rpx;
			font-weight: bold;
		}

		.item {
			border-bottom: solid 2rpx $u-border-color;
		}

		.reply {
			padding: 20rpx;
			background-color: rgb(242, 242, 242);
			border-radius: 12rpx;
			margin: 10rpx 0;

			.username {
				font-size: 24rpx;
				color: #7a7a7a;
			}
		}
	}
</style>
